package item01;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/21 12:06
 * @Description
 */
public class Book {

    private String name;
    private double price;

    private Book(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public static Book createEnglishBook(double price) {
        return new Book("English", price);
    }

    public static Book of(String name, double price) {
        if (name == null || price < 0) {
            throw new IllegalArgumentException("参数不合法");
        }
        return new Book(name, price);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public static void main(String[] args) {
        Book book = Book.createEnglishBook(100);
        System.out.println(book.getName());
        System.out.println(book.getPrice());
        Book book1 = Book.of("Java", 100);
        System.out.println(book1.getName());
        System.out.println(book1.getPrice());
    }
}
